import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const os = require('node:os');

export function createNetworkHandler(app, logger) {
  // 获取映射文件
  app.get('/network/info', async (req, res) => {
    try {
      res.send({
        code: 200,
        data: os.networkInterfaces(),
        msg: '网络信息',
      });
    } catch (error) {
      logger.error(error);
      res.send({ code: 500, msg: '获取网络信息失败' });
    } finally {
      res.end();
    }
  });
}
